<?php
require_once 'Models/Admin/Dao/AdminBaseDao.php';

class AdminUserDao extends AdminBaseDao {
	private static $tableName = 'admin_user';
	
	public function add($fields) {
		if (!is_array($fields)) return 0;
		return $this->queryHelper()->insert(self::$tableName, $fields);
	}
	
	public function update($userId, $fields) {
		if ($userId <= 0 || !is_array($fields)) return 0;
		return $this->queryHelper()->update(self::$tableName, $fields, 'user_id=?', array($userId));
	}
	
	public function get($userId) {
		$userId = intval($userId);
		return $this->queryHelper()->get(self::$tableName, null, 'user_id=?', array($userId));
	}
	
	public function getByName($userName) {
		if ('' == $userName) return null;
		return $this->queryHelper()->get(self::$tableName, null, 'user_name=?', array($userName));
	}
	
	public function delete($userId) {
		return $this->queryHelper()->delete(self::$tableName, 'user_id=?', array($userId));
	}
	
	public function findAll() {
		return $this->queryHelper()->query(self::$tableName, null, null, null, null, null, 'create_time');
	}
}
